import csv
import codecs
import collections
import io
import sys

PY2 = sys.version_info[0] == 2

_Writer = collections.namedtuple('_Writer', 'writerow writerows')
if PY2:
    pass
else:
    unichr = chr
    text_type = str
    string_types = (str,)
    def to_native(source, encoding='utf-8', falsy_empty=False):
        if not source and falsy_empty:
            return ''

        if isinstance(source, bytes):
            return source.decode(encoding)

        return str(source)
    integer_types = (int,)

    imap = map
    izip = zip
    ifilter = filter

    def implements_to_string(cls):
        return cls

    def implements_iterator(cls):
        return cls

    def reraise(tp, value, tb=None):
        pass

    _reader = codecs.getreader('utf-8')
    _writer = codecs.getwriter('utf-8')
    def csv_reader(stream, **params):
        assert not isinstance(stream, io.TextIOBase), \
            "For cross-compatibility purposes, csv_reader takes a bytes stream"
        return csv.reader(_reader(stream), **params)
    def csv_writer(stream, **params):
        pass

def to_text(source):
    pass